package ym.ecrm.web.action.systemManagement;

import java.util.LinkedList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import ym.ecrm.core.common.util.Pager;
import ym.ecrm.core.dto.systemManagement.ParentRoleComboBoxDTO;
import ym.ecrm.core.dto.systemManagement.RoleDTO;
import ym.ecrm.core.service.systemManagement.ISystemService;
import ym.ecrm.web.action.base.BaseAction;

/**
 * 
 * @author Princess
 * 
 */
public class ParentRoleComboBoxAction extends BaseAction {

	Pager<ParentRoleComboBoxDTO> pager;
	
	@Autowired
	private ISystemService systemService;

	public String execute() {
		Pager<RoleDTO> pager = systemService.findRoles(1, 25);
		this.pager = new Pager<ParentRoleComboBoxDTO>();
		this.pager.setPageNumber(pager.getPageNumber());
		this.pager.setPageSize(pager.getPageSize());
		this.pager.setTotalCount(pager.getTotalCount());
		if(pager.getTotalCount() != 0){
			List<RoleDTO> list = pager.getData();
			List<ParentRoleComboBoxDTO> dist = 
					new LinkedList<ParentRoleComboBoxDTO>();
			for(int i = 0; i < list.size(); i++){
				RoleDTO roleDTO = list.get(i);
				ParentRoleComboBoxDTO parentRoleComboBoxDTO = 
						new ParentRoleComboBoxDTO();
				parentRoleComboBoxDTO.setRoleId(roleDTO.getRoleId());
				parentRoleComboBoxDTO.setRoleName(roleDTO.getRoleName());
				dist.add(parentRoleComboBoxDTO);
			}
			this.pager.setData(dist);
		}
		return proccess();
	}

	public String getErrorMessage() {
		return errorMessage;
	}

	public String getSuccess() {
		return success;
	}

	public Pager<ParentRoleComboBoxDTO> getPager() {
		return pager;
	}

	public void setPager(Pager<ParentRoleComboBoxDTO> pager) {
		this.pager = pager;
	}
	
}
